package io.github.bigbird0101.youyishi.spring.bean.load.statistics;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;

/**
 * <p> AgentBeanFactoryRegister </p>
 *
 * @author fupengpeng
 * @version 1.0
 * @date 2025/6/13 22:10
 */
public class AgentBeanFactoryRegister implements BeanDefinitionRegistryPostProcessor {
    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
        if (!registry.containsBeanDefinition("testController")) {
            AnnotatedGenericBeanDefinition genericBeanDefinition = new AnnotatedGenericBeanDefinition(TestController.class);
            registry.registerBeanDefinition("testController", genericBeanDefinition);
        }
        if (!registry.containsBeanDefinition("beanInitBeanFactory")) {
            AnnotatedGenericBeanDefinition genericBeanDefinition = new AnnotatedGenericBeanDefinition(BeanInitBeanFactory.class);
            registry.registerBeanDefinition("beanInitBeanFactory", genericBeanDefinition);
        }
        if (!registry.containsBeanDefinition("beanLazyLoadBeanDefinitionFactory")) {
            AnnotatedGenericBeanDefinition genericBeanDefinition = new AnnotatedGenericBeanDefinition(BeanLazyLoadBeanDefinitionFactory.class);
            registry.registerBeanDefinition("beanLazyLoadBeanDefinitionFactory", genericBeanDefinition);
        }
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    }
}
